#include "syscall.h"


/* GLOBAL VARIABLES */
	int lock1;
	int lock2;
	int lock3;
	int cond1;
	int	cond2;
	int cond3;
	int mv1;
	int mv2;
	int mv3;

void testInitializer(){

	Printing("T2: initializing everything!\n", ConsoleOutput, 0, 0);
	
	lock1 = 0;
	lock2 = 0;
	lock3 = 0;
	cond1 = 0;
	cond2 = 0;
	cond3 = 0;
	mv1 = 0;
	mv2 = 0;
	mv3 = 0;
	
	lock1 = CreateLock("lock1", 5);
	Printing("T2: lock1 created!\n", ConsoleOutput, 0, 0);
	if(lock1 == -1){
		Printing("T2: Error when trying to create lock 1!\n", ConsoleOutput, 0, 0);
	}
	lock2 = CreateLock("lock2", 5);
	Printing("T2: lock2 created!\n", ConsoleOutput, 0, 0);
	if(lock2 == -1){
		Printing("T2: Error when trying to create lock 2!\n", ConsoleOutput, 0, 0);
	}
	lock3 = CreateLock("lock3", 5);
	Printing("T2: lock3 created!\n", ConsoleOutput, 0, 0);
	if(lock2 == -1){
		Printing("T2: Error when trying to create lock 3!\n", ConsoleOutput, 0, 0);
	}
	
	cond1 = CreateCondition("cond1", 5);
	Printing("T2: cond1 created!\n", ConsoleOutput, 0, 0);
	if(cond1 == -1){
		Printing("T2: Error when trying to create cond1!\n", ConsoleOutput, 0, 0);
	}
	cond2 = CreateCondition("cond2", 5);
	Printing("T2: cond2 created!\n", ConsoleOutput, 0, 0);
	if(cond2 == -1){
		Printing("T2: Error when trying to create cond2!\n", ConsoleOutput, 0, 0);
	}
	cond3 = CreateCondition("cond3", 5);
	Printing("T2: cond3 created!\n", ConsoleOutput, 0, 0);
	if(cond3 == -1){
		Printing("T2: Error when trying to create cond3!\n", ConsoleOutput, 0, 0);
	}

	mv1 = CreateMonitor("mv1", 3);
	Printing("T2: mv1 created!\n", ConsoleOutput, 0, 0);
	if(mv1 == -1){
		Printing("T2: Error when trying to create mv1!\n", ConsoleOutput, 0, 0);
	}
	mv2 = CreateMonitor("mv2", 3);
	Printing("T2: mv2 created!\n", ConsoleOutput, 0, 0);
	if(mv2 == -1){
		Printing("T2: Error when trying to create mv2!\n", ConsoleOutput, 0, 0);
	}
	mv3 = CreateMonitor("mv3", 3);
	Printing("T2: mv3 created!\n", ConsoleOutput, 0, 0);
	if(mv3 == -1){
		Printing("T2: Error when trying to create mv3!\n", ConsoleOutput, 0, 0);
	}
}

int main(){
	testInitializer();
	
	Printing("T2: Attempting to acquire lock 2\n", ConsoleOutput, 0, 0);
	AcquireLock("lock2", 5);
	Printing("T2: Attempting to set mv2 to 1.\n", ConsoleOutput, 0, 0);
	SetMonitor("mv2 ", 4, 1, 0);
	Printing("T2: Acquired lock 2.  Will now hold until monitor is set.\n", ConsoleOutput, 0, 0);
	while(GetMonitor("mv3 ", 4, 0)!=1){
		Yield();
	}
	/*Printing("T2: Monitor set, about to Release lock 2\n", ConsoleOutput, 0, 0);
	ReleaseLock("lock2", 5);
	*/
	Printing("T2: About to exit\n", ConsoleOutput, 0, 0);
	
	Exit(0);
	
return;
}